package com.林子祺.CAT旅游系统.dao.ticketmanagement;

import com.林子祺.CAT旅游系统.entity.ticket.TicketData;

import java.sql.*;

public class TicketPull {

    public static void pull(int id){
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelsys", "root", "@Blink102417");

            String sql = "select * from ticket where place_id = "+id;

            stmt = conn.createStatement();

            rs = stmt.executeQuery(sql);

            while (rs.next()) {
                TicketData.InputData(rs.getInt("ticket_id"),rs.getInt("place_id"),rs.getString("time"),rs.getDouble("cost"),rs.getInt("left1"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }

}
